﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.Web;
using Project.Module.Model;
using Project.Engine.Utilities;
using Project.Module.DAO.BL;
using System.Web.SessionState;

namespace Project.Module.Controller
{
    public class EventController
    {
    }

    public partial class HomeController {
        

        [AcceptVerbs(HttpVerbs.Post)]
        public JsonResult SendComment(string comment, string url){
            int idEvent = ProcessUrl.GetIdByUrl(url);

            if (Session["username"] != null && ConvertUtil.ToString(Session["username"]).Length > 0)
            {
                string name = ConvertUtil.ToString(Session["username"]);
                (new EventBL()).InsertComment(name, comment, idEvent);
            } else {
                string name = "khách";
                (new EventBL()).InsertComment(name, comment, idEvent); 
            }

            return Json(new { result = 0 }, JsonRequestBehavior.AllowGet);  
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public JsonResult SendCommentProduct(string comment, string url)
        {
            int idProduct = ProcessUrl.GetIdByUrl(url);

            if (Session["username"] != null && ConvertUtil.ToString(Session["username"]).Length > 0)
            {
                string name = ConvertUtil.ToString(Session["username"]);
                (new EventBL()).InsertCommentProduct(name, comment, idProduct);
            }
            else
            {
                string name = "khách";
                (new EventBL()).InsertCommentProduct(name, comment, idProduct);
            }

            return Json(new { result = 0 }, JsonRequestBehavior.AllowGet);
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public JsonResult AddEvent(string title, HttpPostedFileBase image, string desc)
        {
            var file = System.IO.Path.GetFileName(image.FileName);
            string linkImage = this.Server.MapPath(@"/Frontend/images/anh_sp/") + file;
            image.SaveAs(linkImage);

            ImageBL img = new ImageBL();

            return Json(new { result = 0 }, JsonRequestBehavior.AllowGet);
        }
    }
}
